{% extends "ipr/search_result.html" %}
{# Copyright The IETF Trust 2015, All Rights Reserved #}
{% load origin %}{% origin %}

{% load ietf_filters static %}

{% block pagehead %}
    <link rel="stylesheet" href="{% static "ietf/css/list.css" %}">
{% endblock %}

{% block search_header %}Document IPR search results<br><small class="text-body-secondary">{{doc}}</small>{% endblock %}

{% block search_result %}
    <p class="alert alert-info my-3">Total number of IPR disclosures found: <b>{{ iprs|length }}</b>.</p>

    {% if iprs %}
        <table class="table table-sm table-striped tablesorter">
            <thead>
                <tr>
                    <th scope="col" data-sort="date">Date</th>
                    <th scope="col" data-sort="id">ID</th>
                    <th scope="col" data-sort="statement">Statement</th>
                </tr>
            </thead>

            <tbody>
                {% for ipr in iprs %}
                    <tr>
                        <td>{{ ipr.time|date:"Y-m-d" }}</td>
                        <td>{{ ipr.id }}</td>
                        <td><a href="{% url "ietf.ipr.views.show" id=ipr.id %}">{{ ipr.title }}</a>{% if ipr.state_id == 'removed' or ipr.state_id == 'removed_objfalse' %}<span class="badge rounded-pill text-bg-info">Removed</span>{% endif %}
                            {% if ipr.updates %} <br>(Updates ID#: {% for upd in ipr.updates %}{{upd.target_id}}{% if not forloop.last %}, {% endif %}{% endfor %}){% endif %}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
        {% if related_iprs %}
            <p class="alert alert-warning my-3">
                IPR declarations exist for related documents, <a href="#related">see below</a>.
                    These cannot be assumed to apply to the current document without closer inspection.
            </p>
        {% endif %}
    {% endif %}

    <p class="alert alert-info my-3">Total number of documents searched: <b>{{ docs|length}}</b>.</p>

    <table class="table table-sm table-striped tablesorter">
        <thead>
            <tr>
                <th scope="col" data-sort="date">Date</th>
                <th scope="col" data-sort="id">ID</th>
                <th scope="col" data-sort="statement">Statement</th>
            </tr>
        </thead>

        {% for d in docs %}
            <tbody>
                <tr>
                    <th scope="col" class="table-info" colspan="3">
                        Results for {{ d.name|prettystdname|urlize_ietf_docs }}
                        ("{{ d.title }}"){% if d != doc and d.related %}, which
                            {% if d == d.related.source %}
                                {{ d.relation|lower }}
                                {{ d.related.target|prettystdname|urlize_ietf_docs }}
                                ("{{ d.related.target.title }}")
                            {% else %}
                                was {{ d.relation|lower }}
                                {{ d.related.source|prettystdname|urlize_ietf_docs }}
                                ("{{ d.related.source.title }}")
                            {% endif %}
                        {% endif %}
                    </th>
                </tr>
            </tbody>
            <tbody>
                {% with d.iprdocrel_set.all as doc_iprs %}
                    {% if doc_iprs %}
                        {% for ipr in doc_iprs %}
                            {% if ipr.disclosure.state_id in states %}
                                <tr>
                                    <td>{{ ipr.disclosure.time|date:"Y-m-d" }}</td>
                                    <td>{{ ipr.disclosure.id }}</td>
                                    <td><a href="{% url "ietf.ipr.views.show" id=ipr.disclosure.id %}">{{ ipr.disclosure.title }}</a>{% if ipr.disclosure.state_id == 'removed' or ipr.disclosure.state_id == 'removed_objfalse' %} (Removed) {% endif %}
                                        {% if ipr.disclosure.updates %} <br>(Updates ID#: {% for upd in ipr.disclosure.updates %}{{upd.target_id}}{% if not forloop.last %}, {% endif %}{% endfor %}){% endif %}
                                    </td>
                                </tr>
                            {% endif %}
                        {% endfor %}
                    {% else %}
                        <tr>
                            <td></td>
                            <td></td>
                            <td>
                                No IPR disclosures have been submitted directly on {{ d.name|prettystdname|urlize_ietf_docs }}{% if iprs %},
                                    but there are disclosures on {% if docs|length == 2 %}a related document{% else %}related documents{% endif %}, listed on this page{% endif %}.
                            </td>
                        </tr>
                    {% endif %}
                {% endwith %}
            </tbody>
        {% endfor %}
    </table>

    {% if related_iprs %}
        <p class="alert alert-info my-3" id="related">Total number of possibly related IPR disclosures found: <b>{{ related_iprs|length }}</b>.</p>

        <table class="table table-sm table-striped tablesorter">
            <thead>
                <tr>
                    <th scope="col">Date</th>
                    <th scope="col">ID</th>
                    <th scope="col">Statement</th>
                </tr>
            </thead>

            <tbody>
                {% for ipr in related_iprs %}
                    <tr>
                        <td>{{ ipr.time|date:"Y-m-d" }}</td>
                        <td>{{ ipr.id }}</td>
                        <td><a href="{% url "ietf.ipr.views.show" id=ipr.id %}">{{ ipr.title }}</a>
                            {% if ipr.updates %} <br>(Updates ID#: {% for upd in ipr.updates %}{{upd.target_id}}{% if not forloop.last %}, {% endif %}{% endfor %}){% endif %}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}


{% endblock %}

{% block js %}
    <script src="{% static "ietf/js/list.js" %}"></script>
{% endblock %}